package br.com.jvet.entidade;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "tbhistoricoclinico")
@SequenceGenerator(name = "historico_seq", sequenceName = "historico_seq", initialValue = 1, allocationSize = 1)
public class HistoricoClinico implements Serializable {

	private static final long serialVersionUID = 6928938701654981383L;
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "historico_seq")
	private int codigo;
	@Column
	@Temporal(TemporalType.DATE)
	private Date data;
	@Column
	@Temporal(TemporalType.TIME)
	private Date hora;
	@OneToOne
	private Animal animal;
	@OneToOne
	private Usuario usuario;
	@OneToOne
	private Funcionario medico;
	@Column(length = 500)
	private String observacao;

	public HistoricoClinico() {
		super();
		criarObjetos();
	}

	public void criarObjetos() {
		animal = new Animal();
		usuario = new Usuario();
		medico = new Funcionario();
		data = new Date();
		hora = new Date();
	}

	public int getCodigo() {
		return codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data = data;
	}

	public Animal getAnimal() {
		return animal;
	}

	public void setAnimal(Animal animal) {
		this.animal = animal;
	}

	public Usuario getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	public Funcionario getMedico() {
		return medico;
	}

	public void setMedico(Funcionario medico) {
		this.medico = medico;
	}

	public Date getHora() {
		return hora;
	}

	public void setHora(Date hora) {
		this.hora = hora;
	}

	public String getObservacao() {
		return observacao;
	}

	public void setObservacao(String observacao) {
		this.observacao = observacao;
	}

	@Override
	public String toString() {
		return "HistoricoClinico [codigo=" + codigo + ", data=" + data
				+ ", animal=" + animal + ", usuario=" + usuario + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((animal == null) ? 0 : animal.hashCode());
		result = prime * result + codigo;
		result = prime * result + ((data == null) ? 0 : data.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HistoricoClinico other = (HistoricoClinico) obj;
		if (animal == null) {
			if (other.animal != null)
				return false;
		} else if (!animal.equals(other.animal))
			return false;
		if (codigo != other.codigo)
			return false;
		if (data == null) {
			if (other.data != null)
				return false;
		} else if (!data.equals(other.data))
			return false;
		return true;
	}
	
	public HistoricoClinico clone(){
		HistoricoClinico hist = new HistoricoClinico();
		hist.setCodigo(codigo);
		hist.setAnimal(animal);
		hist.setData(data);
		hist.setHora(hora);
		hist.setMedico(medico);
		hist.setObservacao(observacao);
		hist.setUsuario(usuario);
		
		return hist;
	}

}
